package com.yexiao.cofe.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yexiao.cofe.business.pojo.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author lkl
 * @since 2025/4/8
 */
@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {

    @Select("select * from permission where permission_id = #{permissionId}")
    Permission selectByPermissionId(@Param("permissionId") String permissionId);

    @Select("select * from permission where father_permission_id = #{fatherPermissionId}")
    List<Permission> listByFatherPermissionId(@Param("fatherPermissionId") String fatherPermissionId);

    @Select("select count(*) from permission where father_permission_id = #{fatherPermissionId}")
    int countChildPermission(String fatherPermissionId);

    @Delete("delete from permission where permission_id = #{permissionId}")
    void delByPermissionId(String permissionId);

    void update(@Param("permissionId") String permissionId,
                @Param("permissionName") String permissionName,
                @Param("fatherPermissionId") String fatherPermissionId,
                @Param("fatherPermissionName") String fatherPermissionName,
                @Param("sort") Integer sort);

    void updateChild(@Param("oldFatherPermissionId") String oldFatherPermissionId,
                     @Param("newFatherPermissionId") String newFatherPermissionId,
                     @Param("fatherPermissionName") String fatherPermissionName);

    @Select("select * from permission")
    List<Permission> listAll();

    List<Permission> listPermission(@Param("roleId") List<Integer> roleIdList);

    List<Permission> listByRoleId(Integer roleId);

    List<Permission> listUserPermission(@Param("storeId") String storeId, @Param("userId") String userId);
}
